package com.woniu.service.impl;

import com.woniu.domain.Feedback;
import com.woniu.mapper.FeedbackMapper;
import com.woniu.service.FeedbackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.domain.Feedback;
import com.woniu.mapper.FeedbackMapper;
import com.woniu.service.FeedbackService;
import com.woniu.vo.PositionVo;
import com.woniu.vo.RFVo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyy
 * @author xiayang
 * @since 2021-03-09
 */
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {
    @Resource
    private FeedbackMapper feedbackMapper;

    @Override
    public IPage<RFVo> getPage(PositionVo positionVo, Integer uid, String status) {
        Page<RFVo> page=new Page<>(positionVo.getCurrent(),positionVo.getSize());
        QueryWrapper<RFVo> wrapper = new QueryWrapper<>();
        wrapper.eq("up.uid",uid);
        wrapper.eq("f.`status`",status);
        return feedbackMapper.getRfPage(page,wrapper);
    }

    @Override
    @Cacheable(cacheNames = "getPg", key = "129")
    public IPage<RFVo> getPg(PositionVo positionVo, Integer uid) {
        Page<RFVo> page=new Page<>(positionVo.getCurrent(),positionVo.getSize());
        QueryWrapper<RFVo> wrapper = new QueryWrapper<>();
        wrapper.eq("up.uid",uid);
        return feedbackMapper.getRfPage(page,wrapper);
    }

    @Override
    @CacheEvict(cacheNames = "getPg" , key = "129")
    public void updateR(String id,String status) {
        QueryWrapper<Feedback> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("feedback_id",id);
        Feedback feedback=this.getOne(wrapper1);
        feedback.setStatus(status);

        UpdateWrapper<Feedback> wrapper = new UpdateWrapper<>();
        wrapper.eq("feedback_id",id);
        this.update(feedback,wrapper);
    }

    @Override
    @CacheEvict(cacheNames = "getPg" , key = "129")
    public void deleteP(List<String> Ids) {
        this.removeByIds(Ids);
    }
}
